package com.wyiot.core.utils;

import com.wyiot.core.enums.RHttpStatusEnum;
import lombok.AllArgsConstructor;
import lombok.ConfigurationKeys;
import lombok.Data;
import lombok.ToString;

import javax.validation.constraints.NotNull;

/**
 * @author yly
 * @since 2022年03月30日
 */
@Data
@AllArgsConstructor
@NotNull
@ToString
public class R {
    private Integer code;
    private Object data;
    private String message;

    /**
     * 成功返回只有一种方法
     * @param data
     * @return
     */

    public static R ok(Object data){
        return new R(RHttpStatusEnum.Success.getCode(),data , RHttpStatusEnum.Success.getMessage());
    }
    public R message(String message){
        this.message=message;
        return this;
    }
    /**
     * 失败返回
     * @param data
     * @return
     */
    public static R error(Object data){
        return new R(RHttpStatusEnum.Error.getCode(), data,RHttpStatusEnum.Error.getMessage());
    }
}
